# -*- coding: utf-8 -*-
"""
@Time    : 2024/7/12 11:23 
@Author  : ZhangShenao 
@File    : serial_download.py 
@Desc    : 串行执行网页下载
"""
import requests

from bacis.decorator.perf_log_decorator import perf_log


def download_site(url: str) -> None:
    """
    从网页下载内容
    :param url: 网页url
    :return:
    """
    resp = requests.get(url)
    print(f'download {len(resp.content)} from {url}')


def download_all_sites(site_urls: list[str]) -> None:
    """
    从多个网页下载内容
    :param site_urls: 网页url列表
    """
    for url in site_urls:
        download_site(url)


@perf_log
def run():
    sites = [
        'https://en.wikipedia.org/wiki/Portal:Arts',
        'https://en.wikipedia.org/wiki/Portal:History',
        'https://en.wikipedia.org/wiki/Portal:Society',
        'https://en.wikipedia.org/wiki/Portal:Biography',
        'https://en.wikipedia.org/wiki/Portal:Mathematics',
        'https://en.wikipedia.org/wiki/Portal:Science',
        'https://en.wikipedia.org/wiki/Computer_science',
        'https://en.wikipedia.org/wiki/Python_(programming_language)',
        'https://en.wikipedia.org/wiki/Java_(programming_language)',
        'https://en.wikipedia.org/wiki/PHP',
        'https://en.wikipedia.org/wiki/Node.js',
        'https://en.wikipedia.org/wiki/The_C_Programming_Language',
        'https://en.wikipedia.org/wiki/Go_(programming_language)'
    ]
    download_all_sites(sites)


run()
